package com.ruoyi.cmelasercladding.service.impl;

import com.ruoyi.cmelasercladding.domain.ZsCladdingProcess;
import com.ruoyi.cmelasercladding.domain.ZsCladdingUrl;
import com.ruoyi.cmelasercladding.domain.ZxLaserCladdingOrderForm;
import com.ruoyi.cmelasercladding.mapper.ZsCladdingProcessMapper;
import com.ruoyi.cmelasercladding.mapper.ZsCladdingUrlMapper;
import com.ruoyi.cmelasercladding.mapper.ZxLaserCladdingOrderFormMapper;
import com.ruoyi.cmelasercladding.service.IZxLaserCladdingOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * LaserCladdingOrderService业务层处理
 * 
 * @author zhangxu
 * @date 2021-12-16
 */
@Service
public class ZxLaserCladdingOrderFormServiceImpl implements IZxLaserCladdingOrderFormService 
{
    @Autowired
    private ZxLaserCladdingOrderFormMapper zxLaserCladdingOrderFormMapper;
    @Autowired
    private ZsCladdingProcessMapper zsCladdingProcessMapper;

    @Autowired
    private ZsCladdingUrlMapper zsCladdingUrlMapper;
    /**
     * 查询LaserCladdingOrder
     * 
     * @param id LaserCladdingOrder主键
     * @return LaserCladdingOrder
     */
    @Override
    public ZxLaserCladdingOrderForm selectZxLaserCladdingOrderFormById(Long id)
    {
        return zxLaserCladdingOrderFormMapper.selectZxLaserCladdingOrderFormById(id);
    }

    /**
     * 查询LaserCladdingOrder列表
     * 
     * @param zxLaserCladdingOrderForm LaserCladdingOrder
     * @return LaserCladdingOrder
     */
    @Override
    public List<ZxLaserCladdingOrderForm> selectZxLaserCladdingOrderFormList(ZxLaserCladdingOrderForm zxLaserCladdingOrderForm)
    {
        return zxLaserCladdingOrderFormMapper.selectZxLaserCladdingOrderFormList(zxLaserCladdingOrderForm);
    }

    /**
     * 新增LaserCladdingOrder
     * 
     * @param zxLaserCladdingOrderForm LaserCladdingOrder
     * @return 结果
     */
    @Override
    public int insertZxLaserCladdingOrderForm(ZxLaserCladdingOrderForm zxLaserCladdingOrderForm)
    {
        ZsCladdingProcess zsCladdingProcess = new ZsCladdingProcess();
        zsCladdingProcess.setOrderId(zxLaserCladdingOrderForm.getOrderId());
        zsCladdingProcessMapper.insertZsCladdingProcess(zsCladdingProcess);

        //url
        ZsCladdingUrl zsCladdingUrl = new ZsCladdingUrl();
        zsCladdingUrl.setOederid(zxLaserCladdingOrderForm.getOrderId());
        zsCladdingUrlMapper.insertZsCladdingUrl(zsCladdingUrl);


        return zxLaserCladdingOrderFormMapper.insertZxLaserCladdingOrderForm(zxLaserCladdingOrderForm);


    }

    /**
     * 修改LaserCladdingOrder
     * 
     * @param zxLaserCladdingOrderForm LaserCladdingOrder
     * @return 结果
     */
    @Override
    public int updateZxLaserCladdingOrderForm(ZxLaserCladdingOrderForm zxLaserCladdingOrderForm)
    {
        return zxLaserCladdingOrderFormMapper.updateZxLaserCladdingOrderForm(zxLaserCladdingOrderForm);
    }

    /**
     * 批量删除LaserCladdingOrder
     * 
     * @param ids 需要删除的LaserCladdingOrder主键
     * @return 结果
     */
    @Override
    public int deleteZxLaserCladdingOrderFormByIds(Long[] ids)
    {
        ZxLaserCladdingOrderForm zxLaserCladdingOrderForm=null;
        ZsCladdingProcess zsCladdingProcess=null;
        List<ZsCladdingProcess> zsCladdingProcesses=null;
        int i=0;
        if (ids.length>0){
            for (long id:ids){
                i=0;
                zxLaserCladdingOrderForm = zxLaserCladdingOrderFormMapper.selectZxLaserCladdingOrderFormById(id);
                zsCladdingProcess = new ZsCladdingProcess();
                zsCladdingProcess.setOrderId(zxLaserCladdingOrderForm.getOrderId());
                zsCladdingProcesses = zsCladdingProcessMapper.selectZsCladdingProcessList(zsCladdingProcess);
                zsCladdingProcessMapper.deleteZsCladdingProcessById(zsCladdingProcesses.get(0).getId());
                i++;
            }
        }



        return zxLaserCladdingOrderFormMapper.deleteZxLaserCladdingOrderFormByIds(ids);
    }

    /**
     * 删除LaserCladdingOrder信息
     * 
     * @param id LaserCladdingOrder主键
     * @return 结果
     */
    @Override
    public int deleteZxLaserCladdingOrderFormById(Long id)
    {
        ZxLaserCladdingOrderForm zxLaserCladdingOrderForm = zxLaserCladdingOrderFormMapper.selectZxLaserCladdingOrderFormById(id);


        ZsCladdingProcess zsCladdingProcess = new ZsCladdingProcess();
        zsCladdingProcess.setOrderId(zxLaserCladdingOrderForm.getOrderId());
        List<ZsCladdingProcess> zsCladdingProcesses = zsCladdingProcessMapper.selectZsCladdingProcessList(zsCladdingProcess);
        zsCladdingProcessMapper.deleteZsCladdingProcessById(zsCladdingProcesses.get(0).getId());


        return zxLaserCladdingOrderFormMapper.deleteZxLaserCladdingOrderFormById(id);
    }
    /**
     * 根据日期查询ZxLaserCladdingOrderForm结果
     *
     * @param begainDate 需要查询的日期
     * @return 结果
     */
    @Override
    public List<ZxLaserCladdingOrderForm> selectZxLaserCladdingOrderFormBydate(Date begainDate) {
        return zxLaserCladdingOrderFormMapper.selectZxLaserCladdingOrderFormBydate(begainDate);
    }
}
